package cn.tedu._05weibo1.controller;

import cn.tedu._05weibo1.mapper.UserMapper;
import cn.tedu._05weibo1.pojo.dto.UserRegDTO;
import cn.tedu._05weibo1.pojo.entity.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;

@RestController
@RequestMapping("v1/users/")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @PostMapping("reg")
    public int userReg(@RequestBody UserRegDTO userDTO, HttpSession session) {
        if(userMapper.selectByUsername(userDTO.getUsername()) != null){
            return 2;
        }
        User user = new User();
        BeanUtils.copyProperties(userDTO,user);
        user.setCreated(new Date());
        userMapper.insert(user);
        return 1;
    }

//    @PostMapping("login")
//    public int userLogin(){
//        return 1;
//    }

}
